package com.localjoycommunity.cpdj.project.system.service.impl;

import java.util.List;

import com.localjoycommunity.cpdj.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.localjoycommunity.cpdj.project.system.mapper.SysLearnDataMapper;
import com.localjoycommunity.cpdj.project.system.domain.SysLearnData;
import com.localjoycommunity.cpdj.project.system.service.ISysLearnDataService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 学习资料Service业务层处理
 *
 * @author leepandar
 * @date 2020-10-30
 */
@Service
public class SysLearnDataServiceImpl implements ISysLearnDataService {
    @Autowired
    private SysLearnDataMapper sysLearnDataMapper;

    /**
     * 查询学习资料
     *
     * @param learnId 学习资料ID
     * @return 学习资料
     */
    @Override
    public SysLearnData selectSysLearnDataById(Long learnId) {
        return sysLearnDataMapper.selectSysLearnDataById(learnId);
    }

    /**
     * 查询学习资料app
     *
     * @param learnId 学习资料ID
     * @return 学习资料
     */
    @Override
    public SysLearnData selectSysLearnDataByIdApp(Long learnId) {
        SysLearnData sysLearnData = sysLearnDataMapper.selectSysLearnDataById(learnId);
        SysLearnData learnData = new SysLearnData();
        learnData.setLearnId(sysLearnData.getLearnId());
        learnData.setReadNum(sysLearnData.getReadNum()+1);
        sysLearnDataMapper.updateSysLearnData(learnData);
        return sysLearnData;
    }

    /**
     * 查询学习资料列表
     *
     * @param sysLearnData 学习资料
     * @return 学习资料
     */
    @Override
    public List<SysLearnData> selectSysLearnDataList1(SysLearnData sysLearnData) {
        return sysLearnDataMapper.selectSysLearnDataList1(sysLearnData);
    }
    @Override
    public List<SysLearnData> selectSysLearnDataList(SysLearnData sysLearnData) {
        return sysLearnDataMapper.selectSysLearnDataList(sysLearnData);
    }

    /**
     * 新增学习资料
     *
     * @param sysLearnData 学习资料
     * @return 结果
     */
    @Override
    public int insertSysLearnData(SysLearnData sysLearnData) {
        sysLearnData.setCreateTime(DateUtils.getNowDate());
        return sysLearnDataMapper.insertSysLearnData(sysLearnData);
    }

    /**
     * 修改学习资料
     *
     * @param sysLearnData 学习资料
     * @return 结果
     */
    @Override
    public int updateSysLearnData(SysLearnData sysLearnData) {
        sysLearnData.setUpdateTime(DateUtils.getNowDate());
        return sysLearnDataMapper.updateSysLearnData(sysLearnData);
    }

    /**
     * 批量删除学习资料
     *
     * @param learnIds 需要删除的学习资料ID
     * @return 结果
     */
    @Override
    public int deleteSysLearnDataByIds(Long[] learnIds) {
        return sysLearnDataMapper.deleteSysLearnDataByIds(learnIds);
    }

    /**
     * 删除学习资料信息
     *
     * @param learnId 学习资料ID
     * @return 结果
     */
    @Override
    public int deleteSysLearnDataById(Long learnId) {
        return sysLearnDataMapper.deleteSysLearnDataById(learnId);
    }

    @Override
    @Transactional
    public int updateDigNum(long id, int num) {
        return sysLearnDataMapper.updateDownLoadNum(id, num);
    }
}
